<template>
  <div id="app"  >
    <router-view v-if="isRouterAlive" ref="rt"  >
      <!-- 这里是不被缓存的视图组件，比如 Edit！ -->
    </router-view>
  </div>
</template>

<script>
import {APP_ID,REDIRECT_URL} from './constants'
export default {
  name: 'App',
  data(){
    return{
      isRouterAlive:true,
      yxcLogo:'http://yxc.cs.12366.com/yxcLogo.png',

    }
  },
  mounted(){

    this.$nextTick(()=>{
        this.initWeixin();

    })




  },
  watch:{
    '$route' (to, from) {

      this.isRouterAlive = false;

      this.$nextTick(()=>{
        this.isRouterAlive = true;
       })
      var  xid = localStorage.getItem('wxUserId') || ''

      if(!xid && to.query.funCode!='yxc_pro'){
        if(to.query.funCode != 'carLogin' && to.query.funCode != 'start' && to.name!='auth') {
          this.$router.push({
            path: '/personCar',
            query: {
              funCode: 'carLogin'
            }
          })
        }

      }

      this.shareTimePage()
      this.shareAppPage()





    }
  },
  methods:{

    shareTimePage(objs={}){
      var curUrl = window.location.href
      var that = this;
      var templink;
      if(objs.type){
        templink = objs.link;
      }else{
        templink = curUrl;
      }
      var openid = localStorage.getItem('WX_UID')?localStorage.getItem('WX_UID'):'';
      if(templink.indexOf('?')>=0){
        if(templink.indexOf('fxopenid')>=0){
          templink = templink;
        }else{
          templink = templink+'&fxopenid='+openid;
        }

      }else{
        if(templink.indexOf('fxopenid')>=0){
          templink = templink;
        }else{
          templink = templink+'?fxopenid='+openid;
        }
      }

      if(objs.type){
        objs = {
          title:objs.title,
          desc:objs.desc,
          link:templink,
          imgUrl:objs.imgUrl
        }
      }else{
        objs = {
          title:'顺利办 优享车',
          desc:'企业共享用车平台',
          link:templink,
          imgUrl:that.yxcLogo
        }
      }
      wx.ready(function () {
        wx.onMenuShareTimeline({
          title:objs.title, // 分享标题
          link: objs.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: objs.imgUrl, // 分享图标
          success: function (res) {
            // alert(JSON.stringify(res));
            // 用户点击了分享后执行的回调函数
            // that.addhist(0,objs.link);
          },
          cancel: function () {
// 用户取消分享后执行的回调函数
          }
        })

      })
    },
    shareAppPage(objs={}){
      var curUrl = window.location.href
      var templink;
      var that = this;
      if(objs.type){
        templink = objs.link;
      }else{
        templink = curUrl;
      }
      var openid = localStorage.getItem('WX_UID')?localStorage.getItem('WX_UID'):'';
      if(templink.indexOf('?')>=0){
        if(templink.indexOf('fxopenid')>=0){
          templink = templink;
        }else{
          templink = templink+'&fxopenid='+openid;
        }
      }else{
        if(templink.indexOf('fxopenid')>=0){
          templink = templink;
        }else{
          templink = templink+'?fxopenid='+openid;
        }
      }
      if(objs.type){
        objs = {
          title:objs.title,
          desc:objs.desc,
          link:templink,
          imgUrl:objs.imgUrl
        }
      }else{
        objs = {
          title:'顺利办 优享车',
          desc:'企业共享用车平台',
          link:templink,
          imgUrl:that.yxcLogo
        }
      }

      // alert(objs.link)
      wx.ready(function () {

        wx.onMenuShareAppMessage({
          title:objs.title, // 分享标题
          desc:objs.desc, // 分享描述
          link:objs.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl:objs.imgUrl, // 分享图标
          type: '', // 分享类型,music、video或link，不填默认为link
          dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
          success: function (res) {
            // alert(JSON.stringify(res));
            // 用户点击了分享后执行的回调函数
            // that.addhist(1,objs.link);
          },
          cancel: function () {
// 用户取消分享后执行的回调函数
          }
        });

      })
    },

    initWeixin(){
      var locationUrl = location.href.split('#')[0];
      // locationUrl = locationUrl.split('?')[0];
      locationUrl = locationUrl;
      // alert(locationUrl)
      this.$http.post('yxc/wxuser/signature',{url:locationUrl,appId:APP_ID}).then(res=>{
        var qm = JSON.parse(res.data);
        console.log(qm)
      wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: qm.appId, // 必填，公众号的唯一标识
        timestamp:qm.timestamp, // 必填，生成签名的时间戳
        nonceStr: qm.noncestr, // 必填，生成签名的随机串
        signature: qm.signature,// 必填，签名，见附录1
        jsApiList: [
          'checkJsApi',
          'onMenuShareTimeline',
          'onMenuShareAppMessage',
          'onMenuShareQQ',
          'onMenuShareWeibo',
          'onMenuShareQZone',
          'hideMenuItems',
          'showMenuItems',
          'hideAllNonBaseMenuItem',
          'showAllNonBaseMenuItem',
          'translateVoice',
          'startRecord',
          'stopRecord',
          'onVoiceRecordEnd',
          'playVoice',
          'onVoicePlayEnd',
          'pauseVoice',
          'stopVoice',
          'uploadVoice',
          'downloadVoice',
          'chooseImage',
          'previewImage',
          'uploadImage',
          'downloadImage',
          'getNetworkType',
          'openLocation',
          'getLocation',
          'hideOptionMenu',
          'showOptionMenu',
          'closeWindow',
          'scanQRCode',
          'chooseWXPay',
          'openProductSpecificView',
          'addCard',
          'chooseCard',
          'openCard'
        ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
      });
      // wx.error(function(res){
      //    alert(JSON.stringify(res))
      // });

    })
    }
  }
}





</script>

<style lang="scss" scoped>
  #loadings{
    position: fixed;
    top:0;left:0;
    width:100%;height:100%;
    z-index: 9999;
  }
  .backPage{
    position:fixed;
    text-align: right;
    bottom:20%;
    .backhome{
      width:78px; height:78px;
      float: right;
      img{
        width:100%;
      }
    }
    .backmodule{
      width:175px; height:45px;
      img{width:100%;}
    }
    left:20px;
    z-index: 9999;
  }
  .pinfos{
    top:0;left:0;
    position: fixed;
    z-index: 9999;
    background:rgba(0,0,0,.5);
    width:100%;
    height:100%;
    .purlc{
      h3{
        padding:50px;
      }
      position: relative;
      margin:0 auto;
      text-align: center;
      top:30%;
      min-height: 300px;
      width:80%;padding:10px;
      background: #FFF;
      a{
        display: block;width:80%;padding:15px; border-radius: 10px;
        background: #4caf50;
        color:#FFF;
        margin:0 auto;
        text-align: center;
      }
      border-radius: 10px;
    }
  }
  .jiangtips{
    width:100%;
    height:100%;
    z-index:9999;
    position: fixed;
    top:0;left:0;
    background: rgba(0,0,0,.6);
    .jiangtips_content{
      .shareimg{

        img{width:100%; display: block;}
      }
      position: relative;
      top:40%;
      border-radius: 10px;
      padding-bottom: 50px;
      span.close{
        position: absolute;
        top:20px;
        width:50px;
        height:50px;
        line-height: 50px;
        text-align: center;
        border-radius: 1000px;
        background: rgba(0,0,0,.5);

        right:20px;
        img{
          width:30px;
          position: relative;
          top:5px;
        }
      }
      .tipsText{
        position: absolute;
        width:90%;
        left:5%;
        text-align: center;
        top:180px;
        color:#FFF;
        font-size:40px;
      }
      .tipact{
        position: absolute;
        bottom:40px;
        width:100%;
        text-align: center;
        left:0;
        button{
          border:none;
          background: #FF002E;
          padding:15px 80px;
          color:#FFF;
          font-size:35px;
          border-radius: 1000px;
          margin-bottom: 30px;
        }
      }
      width: 70%;
      margin:0 auto;

      background: #FFF;
      .completeInfo{
        span{
          font-weight: bold;
          text-decoration: underline;
        }
      }
    }
  }
  #containers{
    position: absolute;
    top:0;left:0;
    width:100%;height: 100%;
    overflow: auto;
  }
.tipsma{
  .logoimg{
    width:80px;
    margin:10px;
    -webkit-border-radius: 10000px;
    -moz-border-radius: 10000px;
    border-radius: 10000px;
  }
  .tipsc{
    text-align: left;
    padding-top:10px;
    h3{ font-size:25px;}
    p{
      font-size:20px;
      a{
        position: absolute;
        top:20px; right:20px;
        color:#f9d783;
        font-weight: bold;
        -webkit-border-radius: 1000px;
        border:2px solid #f9d783;
        -moz-border-radius: 1000px;
        border-radius: 1000px;
        padding:5px 10px;
        font-size:25px;
      }
    }
  }

  top:0;
  left:0;
  width:100%;


  color:#FFF;
  background: rgba(0,0,0,.7);
  z-index: 99;
  text-align: center;
  a{
    color:#f9d783;
    font-weight: bold;
  }

}
.mapic{
  position: fixed;
  top:0;
  text-align: center;
  color:#FFF;
  left:0;
  z-index: 999;
  width:100%;
  height: 100%;
  background: rgba(0,0,0,.8);
  .piccontent{
    img{
      width:100%;
    }

    width:400px;
    position: relative;
    margin:0 auto;
    top:300px;
    border-radius: 10px;
    span{
      color:#999;
      top:50px;
      position: relative;
      border:2px solid #999;
      padding:5px 15px;

      border-radius: 1000px;
    }
  }


}
</style>
